package io.github.wanggit.antrpc.client.config.workers;

import io.github.wanggit.antrpc.IAntrpcContext;
import io.github.wanggit.antrpc.commons.config.CallLogReporterConfig;
import io.github.wanggit.antrpc.commons.config.ConfigChangeTypeEnum;
import io.vavr.collection.List;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class CallLogReporterConfigChangeWorker extends AbstractChangeWorker {

    public CallLogReporterConfigChangeWorker(IAntrpcContext antrpcContext, List<String> prefixs) {
        super(antrpcContext, prefixs);
    }

    @Override
    protected synchronized void internalFired(
            ConfigChangeTypeEnum changeType, String key, String oldValue, String newValue) {
        CallLogReporterConfig callLogReporterConfig =
                getAntrpcContext().getConfiguration().getCallLogReporterConfig();
        setFieldValue(callLogReporterConfig, key, newValue);
        getAntrpcContext()
                .getRpcCallLogHolder()
                .reInitReporters(
                        callLogReporterConfig,
                        getAntrpcContext().getConfiguration(),
                        getAntrpcContext().getSpringApplicationContext());
    }
}
